load("//bazel:tachyon.bzl", "if_has_openmp_on_macos", "if_posix")
load("//bazel:tachyon_cc.bzl", "tachyon_cc_benchmark", "tachyon_cc_library", "tachyon_cc_unittest")

package(default_visibility = ["//visibility:public"])

tachyon_cc_library(
    name = "auto_reset",
    hdrs = ["auto_reset.h"],
    deps = [":logging"],
)

tachyon_cc_library(
    name = "bit_cast",
    hdrs = ["bit_cast.h"],
    deps = [":compiler_specific"],
)

tachyon_cc_library(
    name = "bits",
    srcs = ["bits.cc"],
    hdrs = ["bits.h"],
    deps = [
        ":compiler_specific",
        ":logging",
        "//tachyon/build:build_config",
    ],
)

tachyon_cc_library(
    name = "compiler_specific",
    hdrs = ["compiler_specific.h"],
    deps = ["//tachyon/build:build_config"],
)

tachyon_cc_library(
    name = "cxx20_is_constant_evaluated",
    hdrs = ["cxx20_is_constant_evaluated.h"],
)

tachyon_cc_library(
    name = "endian",
    srcs = ["endian.cc"],
    hdrs = ["endian.h"],
    deps = [":logging"],
)

tachyon_cc_library(
    name = "endian_utils",
    hdrs = ["endian_utils.h"],
    deps = ["//tachyon/build:build_config"],
)

tachyon_cc_library(
    name = "environment",
    srcs = if_posix([
        "environment_posix.cc",
    ]),
    hdrs = ["environment.h"],
    deps = ["//tachyon:export"],
)

tachyon_cc_library(
    name = "immediate_crash",
    hdrs = ["immediate_crash.h"],
    deps = ["//tachyon/build:build_config"],
)

tachyon_cc_library(
    name = "logging",
    srcs = ["logging.cc"],
    hdrs = ["logging.h"],
    deps = [
        "//tachyon:export",
        "@com_github_google_glog//:glog",
    ],
)

tachyon_cc_library(
    name = "maybe_owned",
    hdrs = ["maybe_owned.h"],
    deps = [":maybe_owned_traits"],
)

tachyon_cc_library(
    name = "maybe_owned_traits",
    hdrs = ["maybe_owned_traits.h"],
    deps = ["@com_google_absl//absl/types:span"],
)

tachyon_cc_library(
    name = "no_destructor",
    hdrs = ["no_destructor.h"],
)

tachyon_cc_library(
    name = "openmp_util",
    hdrs = ["openmp_util.h"],
    deps = if_has_openmp_on_macos(["@local_config_omp//:omp"]),
)

tachyon_cc_library(
    name = "optional",
    hdrs = ["optional.h"],
    deps = [":logging"],
)

tachyon_cc_library(
    name = "parallelize",
    hdrs = ["parallelize.h"],
    deps = [
        ":openmp_util",
        "//tachyon/base/functional:functor_traits",
        "@com_google_absl//absl/types:span",
    ],
)

tachyon_cc_library(
    name = "profiler",
    srcs = ["profiler.cc"],
    hdrs = ["profiler.h"],
    deps = [
        "//tachyon:export",
        "//tachyon/base/files:file",
        "@perfetto",
    ],
)

tachyon_cc_library(
    name = "random",
    srcs = ["random.cc"],
    hdrs = ["random.h"],
    deps = [
        ":logging",
        ":range",
        "//tachyon:export",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/numeric:int128",
        "@com_google_absl//absl/random",
    ],
)

tachyon_cc_library(
    name = "range",
    hdrs = ["range.h"],
    deps = ["@com_google_absl//absl/strings"],
)

tachyon_cc_library(
    name = "ref",
    hdrs = ["ref.h"],
    deps = ["@com_google_absl//absl/hash"],
)

tachyon_cc_library(
    name = "scoped_generic",
    hdrs = ["scoped_generic.h"],
    deps = [":logging"],
)

tachyon_cc_library(
    name = "sort",
    hdrs = ["sort.h"],
    deps = [
        "@pdqsort",
        "@powersort",
    ],
)

tachyon_cc_library(
    name = "static_storage",
    hdrs = ["static_storage.h"],
    deps = [":no_destructor"],
)

tachyon_cc_library(
    name = "template_util",
    hdrs = ["template_util.h"],
)

tachyon_cc_library(
    name = "type_list",
    hdrs = ["type_list.h"],
)

tachyon_cc_benchmark(
    name = "sort_benchmark",
    srcs = ["sort_benchmark.cc"],
    deps = [
        "//tachyon/base:random",
        "//tachyon/base:sort",
        "//tachyon/base/containers:container_util",
    ],
)

tachyon_cc_unittest(
    name = "base_unittests",
    srcs = [
        "auto_reset_unittest.cc",
        "bit_cast_unittest.cc",
        "bits_unittest.cc",
        "cxx20_is_constant_evaluated_unittest.cc",
        "endian_utils_unittest.cc",
        "environment_unittest.cc",
        "parallelize_unittest.cc",
        "random_unittest.cc",
        "range_unittest.cc",
        "ref_unittest.cc",
        "scoped_generic_unittest.cc",
    ],
    deps = [
        ":auto_reset",
        ":bit_cast",
        ":bits",
        ":cxx20_is_constant_evaluated",
        ":endian_utils",
        ":environment",
        ":parallelize",
        ":random",
        ":range",
        ":ref",
        ":scoped_generic",
        "//tachyon/base/containers:container_util",
        "//tachyon/base/containers:contains",
        "//tachyon/base/containers:cxx20_erase",
        "@com_google_absl//absl/hash:hash_testing",
    ],
)
